package com.trdcore.zyzkt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trdcore.zyzkt.model.live.LiveCourse;
import com.trdcore.zyzkt.model.live.LiveCourseAccount;
import com.trdcore.zyzkt.resp.ResultData;
import com.trdcore.zyzkt.service.LiveCourseAccountService;
import com.trdcore.zyzkt.service.LiveCourseService;
import com.trdcore.zyzkt.vo.live.LiveCourseConfigVo;
import com.trdcore.zyzkt.vo.live.LiveCourseFormVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 直播课程表 前端控制器
 * </p>
 *
 * @author Luffy
 * @since 2024-03-22
 */
@RestController
@RequestMapping(value="/admin/live/liveCourse")
public class LiveCourseController {

    @Autowired
    private LiveCourseService liveCourseService;

    @Autowired
    private LiveCourseAccountService liveCourseAccountService;


    @Operation(summary = "获取分页列表",description = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public ResultData index(
            @Parameter(name = "page", description = "当前页码", required = true)
            @PathVariable("page") Long page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Long limit) {
        Page<LiveCourse> pageParam = new Page<>(page, limit);
        IPage<LiveCourse> pageModel = liveCourseService.selectPage(pageParam);
        return ResultData.success(pageModel);
    }

    @Operation(summary = "新增",description = "新增")
    @PostMapping("save")
    public ResultData save(@RequestBody LiveCourseFormVo liveCourseVo) {
        LiveCourse liveCourse=new LiveCourse();
        BeanUtils.copyProperties(liveCourseVo,liveCourse);
        liveCourseService.save(liveCourseVo);
        return ResultData.success(null);
    }

    @Operation(summary = "删除",description = "删除")
    @DeleteMapping("remove/{id}")
    public ResultData remove(@PathVariable("id") Long id) {
        liveCourseService.removeLive(id);
        return ResultData.success(null);
    }

    @Operation(summary = "获取",description = "获取")
    @GetMapping("get/{id}")
    public ResultData<LiveCourse> get(@PathVariable("id") Long id) {
        LiveCourse liveCourse = liveCourseService.getById(id);
        return ResultData.success(liveCourse);
    }

    @Operation(summary = "获取",description = "获取")
    @GetMapping("getInfo/{id}")
    public ResultData<LiveCourseFormVo> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(liveCourseService.getLiveCourseFormVo(id));
    }

    @Operation(summary = "修改",description = "修改")
    @PutMapping("update")
    public ResultData updateById(@RequestBody LiveCourseFormVo liveCourseVo) {
        liveCourseService.updateById(liveCourseVo);
        return ResultData.success(null);
    }

    @Operation(summary = "获取",description = "修改")
    @GetMapping("getLiveCourseAccount/{id}")
    public ResultData<LiveCourseAccount> getLiveCourseAccount(@PathVariable("id") Long id) {
        return ResultData.success(liveCourseAccountService.getByLiveCourseId(id));
    }

    @Operation(summary = "获取",description = "修改")
    @GetMapping("getCourseConfig/{id}")
    public ResultData getCourseConfig(@PathVariable("id") Long id) {
        return ResultData.success(liveCourseService.getCourseConfig(id));
    }

    @Operation(summary = "修改配置",description = "修改配置")
    @PutMapping("updateConfig")
    public ResultData updateConfig(@RequestBody LiveCourseConfigVo liveCourseConfigVo) {
        liveCourseService.updateConfig(liveCourseConfigVo);
        return ResultData.success(null);
    }

    @Operation(summary = "获取最近的直播",description="获取最近的直播")
    @GetMapping("findLatelyList")
    public ResultData findLatelyList() {
        return ResultData.success(liveCourseService.findLatelyList());
    }
}

